import { NextRequest, NextResponse } from 'next/server'
import { userQueries } from '@/lib/database-prisma'
import { getUsedColors, USER_COLOR_PALETTE, getColorName } from '@/lib/colors'

export async function GET(request: NextRequest) {
  try {
    // 获取所有用户
    const users = await userQueries.getAll.all() as any[]
    
    // 获取已使用的颜色
    const usedColors = await getUsedColors()
    
    // 获取可用的颜色
    const availableColors = USER_COLOR_PALETTE.filter(color => !usedColors.includes(color))
    
    // 构建用户颜色信息
    const userColors = users.map(user => ({
      id: user.id,
      name: user.name,
      color: user.color,
      colorName: getColorName(user.color),
      created_at: user.created_at
    }))
    
    return NextResponse.json({
      users: userColors,
      usedColors: usedColors.map(color => ({
        color,
        name: getColorName(color)
      })),
      availableColors: availableColors.map(color => ({
        color,
        name: getColorName(color)
      })),
      totalUsers: users.length,
      totalColors: USER_COLOR_PALETTE.length,
      remainingColors: availableColors.length
    })
    
  } catch (error) {
    console.error('获取用户颜色信息失败:', error)
    return NextResponse.json({ error: '服务器错误' }, { status: 500 })
  }
} 